package com.greendragon.persistence.dao.impl; 

import java.util.List;

import org.apache.log4j.Logger;

import com.greendragon.persistence.dao.ICategoryDao;
import com.greendragon.persistence.domain.ProductCategory;
import com.greendragon.persistence.enmu.FetchOrderType;


/** 
 * @author wulibin, exceptsky@gmail.com, 2011-9-24 下午10:15:32
 * 
 */
public class ProductCategoryDaoImpl  extends BaseDao<ProductCategory> implements ICategoryDao<ProductCategory>{
	private static Logger          logger           = Logger.getLogger(ProductCategoryDaoImpl.class);
	
	@Override
	@SuppressWarnings("unchecked")
	public ProductCategory getByName(String name) {
		String hql = "from ProductCategory pc where pc.name = ?";
		try {
			List rs = getHibernateTemplate().find(hql, name);
			if(rs==null || rs.size()==0){
				return null;
			}
			ProductCategory result = (ProductCategory)rs.listIterator().next();
			return result;
		} catch (Exception e) {
			logger.error(e);
			return null;
		}

	}

	@Override
	public List<ProductCategory> getAllRootCategories(int offset, int length, FetchOrderType orderType) {
		String hql = "from ProductCategory as pc where pc.parentCategory is null"+getOrderSql("pc",orderType);
		return selectByPage(hql, null, offset, length);
	}
}
 